package com.lipy.dubboconsumer.controller;

import com.lipy.dubbocommon.entity.Staff;
import com.lipy.dubboconsumer.service.MyCacheableService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("myCache")
public class MyCacheController {
    @Autowired
    MyCacheableService myCacheableService;
    @GetMapping("select/{id}")
    public Object getCache(@PathVariable("id")Integer id){
        System.out.println("MyCacheController.getCache");
        Staff staff = myCacheableService.select2(id);
        return staff;
    }
    @GetMapping("select2/{id}")
    public Object getCache2(@PathVariable("id")Integer id){
        System.out.println("MyCacheController.getCache");
        Staff staff = new Staff();
        staff.setId(id);
        staff.setName("insert");
        Staff staffn = myCacheableService.select(staff);
        return staffn;
    }
    @GetMapping("insert")
    public Object saveStaff(@RequestParam(value = "id",required = false) Integer id){
        Staff staff = new Staff();
        staff.setId(1);
        if(id != null){
            staff.setId(id);
        }
        staff.setName("1namesave");
        myCacheableService.insert(staff);
        System.out.println("MyCacheController.saveStaff");
        return "ok";
    }
    @GetMapping("update")
    public Object updateStaff(){
        Staff staff = new Staff();
        staff.setId(1);
        staff.setName("1namesave");
        int i = myCacheableService.update(staff);
        System.out.println("MyCacheController.updateStaff");
        return "ok" + i;
    }
    @GetMapping("delete/{id}")
    public Object delete(@PathVariable("id") Integer id){
        int delete = myCacheableService.delete(id);
        System.out.println("MyCacheController.delete rows"+delete);
        return delete;
    }
}
